﻿using Abp.Application.Services.Dto;
using Abp.Domain.Repositories;
using Abp.Linq.Extensions;
using RMM.Core.Entity.Shops;
using RMM.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace RMM.Core.ShopService
{
    public class ShopService : EntityDomainService<Shop, long>, IShopService
    {
        private readonly IRepository<Shop, long> _shopRepository;
        private readonly IRepository<ShopProject,int> _projectRepository;


        public ShopService(IRepository<Shop, long> shopRepository
            , IRepository<ShopProject, int> projectRepository)
            :base(shopRepository)
        {
            _shopRepository = shopRepository;
            _projectRepository = projectRepository;
        }


        public Task<List<Shop>> GetShopListAsync(IPagedResultRequest paged)
        {
            var result = _shopRepository.GetAll().PageBy(paged).ToList();
            return Task.FromResult(result);
        }


        public Task<List<Shop>> GetShopListAsync(Expression<Func<Shop, bool>> expression, IPagedResultRequest paged,out int count)
        {
            var result = _shopRepository.GetAll()
                .Where(expression)
                .OrderByDescending(p => p.CreationTime)
                .PageBy(paged)
                .ToList();
            count = result.Count;
            return Task.FromResult(result);
        }

        public Task<IQueryable<ShopProject>> GetShopProjectQueryable()
        {
            return Task.FromResult(_projectRepository.GetAll());
        }


    }
}
